//
//  DDDetailsDescriptionView.m
//  Dingdong
//
//  Created by 程强 on 16/12/9.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDDetailsDescriptionView.h"
#import <WebKit/WKWebView.h>

@interface DDDetailsDescriptionView()<DDDetailsCommentViewDelegate>
@property (strong, nonatomic) WKWebView *desWebView;
@property (strong, nonatomic) DDDetailsCommentView *commentView;
@end

@implementation DDDetailsDescriptionView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.desWebView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [self addSubview:_desWebView];
        
        _commentView = [[DDDetailsCommentView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _commentView.loadMore = NO;
        _commentView.delegate = self;
        [self addSubview:_commentView];
        self.showType = ShowDetailsTypeDescription;
    }
    return self;
}
- (void)commentView:(DDDetailsCommentView *)view refreshCommentWithType:(DingDongCommentType)type
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(descriptionView:refreshComment:)]) {
        [self.delegate descriptionView:self refreshComment:type];
    }
}
- (void)setShowType:(ShowDetailsType)showType
{
    _showType = showType;
    if (showType == ShowDetailsTypeDescription) {
        _desWebView.hidden = NO;
        _commentView.hidden = YES;
    }else{
        _desWebView.hidden = YES;
        _commentView.hidden = NO;
    }
}
- (void)setCommentAry:(NSArray *)commentAry
{
    _commentAry = commentAry;
    _commentView.commentAry = commentAry;
}
- (void)setGoodsInfoUrl:(NSString *)goodsInfoUrl
{
    _goodsInfoUrl = goodsInfoUrl;
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:goodsInfoUrl]];
    [_desWebView loadRequest:request];
}
@end
